package com.zzz.controller;

import com.aaa.vo.Result;
import com.zzz.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：zxw
 * @date ：Created in 2023/3/6 14:12
 */
@RestController
@RequestMapping("good")
@SuppressWarnings("all")
public class SelectController {
    @Autowired
    private GGoodsService goodsService;

    @Autowired
    private UCommentService commentService;

    @Autowired
    private OStockService oStockService;

    @Autowired
    private OOrderService orderService;

    @Autowired
    private UCollectionService uCollectionService;

    @Autowired
    private UAddrService uAddrService;


    //查询商品详细信息
    @RequestMapping("findGoodsById/{id}")
    public Result findGoodsById(@PathVariable Integer id){
        return goodsService.goodsById(id);
    }

    //查询商品所有评论
    @RequestMapping("findComment/{goodsid}/{pageCurrent}/{pageSize}")
    public Result findComment(@PathVariable String goodsid, @PathVariable Integer pageCurrent, @PathVariable Integer pageSize){
        Result result = commentService.commentAndGoodById(goodsid, pageCurrent, pageSize);
        return result;
    }

    //查询商品所有评论下我发表的评论
    @RequestMapping("findMyComment/{goodsid}/{pageCurrent}/{pageSize}")
    public Result findMyComment(@PathVariable String goodsid, @PathVariable Integer pageCurrent, @PathVariable Integer pageSize){
        Result myComment = commentService.findMyComment(goodsid, pageCurrent, pageSize);
        return myComment;
    }

    //查询商品成交数量
    @RequestMapping("getGoodsSellNum/{goodsId}")
    public Result getGoodsSellNum(@PathVariable Integer goodsId){
        Result goodsSellNum = oStockService.getGoodsSellNum(goodsId);
        return goodsSellNum;
    }

    //查询当前商品库存余量
    @RequestMapping("getStock/{goodsId}")
    public Result getStock(@PathVariable Integer goodsId){
        Result stock = oStockService.getStock(goodsId);
        return stock;
    }

    //页面加载判断该用户是否买过该商品
    @RequestMapping("hasBuyThisGoods/{goodsid}")
    public Result hasBuyThisGoods(@PathVariable String goodsid){
        Result buyThisGoods = orderService.hasBuyThisGoods(goodsid);
        return buyThisGoods;
    }

    //查询商品是否已经收藏
    @RequestMapping("isGoodsCollection/{goodsid}")
    public Result isGoodsCollection(@PathVariable String goodsid){
        Result goodsCollection = uCollectionService.isGoodsCollection(goodsid);
        return goodsCollection;
    }

    //查询店铺是否已经关注
    @RequestMapping("isCollectionBusiness/{bid}")
    public Result isCollectionBusiness(@PathVariable String bid){
        Result collectionBusiness = uCollectionService.isCollectionBusiness(bid);
        return collectionBusiness;
    }

    //获取当前用户所有收获地址
    @RequestMapping("getAllAddr")
    public Result getAllAddr(){
        Result allAddr = uAddrService.getAllAddr();
        return allAddr;
    }
 }
